﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class AdminApplyDao
    {
        private MyDbContext DbContext = new MyDbContext();

        public List<Apply> getAllApplyCheck(string role)
        {
            if (role == "school")
            {
                return DbContext.Applies.Where(p => p.isCheck == 1 && p.check_progress != 1).ToList();
            }

            if (role == "bureau")
            {
                return DbContext.Applies.Where(p => p.isCheck == 1 && p.isCityCheck == 1).ToList();
            }

            return null;
        }

        public void updateApply(Apply apply)
        {
            Apply updateApply = DbContext.Applies.Where(p => p.apply_id == apply.apply_id).ToList().First();

            updateApply.check_progress = apply.check_progress;
            updateApply.fail_remark = apply.fail_remark;
            updateApply.isCityCheck = apply.isCityCheck;
            updateApply.isCheck = apply.isCheck;

            DbContext.Update(updateApply);
            DbContext.SaveChanges();
        }

        public List<Apply> getAllReject(string role)
        {
            if (role == "school")
            {
                return DbContext.Applies.Where(p => p.isCheck == -1).ToList();
            }

            if (role == "bureau")
            {
                return DbContext.Applies.Where(p => p.isCheck == -1 && p.isCityCheck == 1).ToList();
            }

            return null;
        }
    }
}